package com.ruoyi.system.service.impl;

import java.security.Key;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.FinancialKeyword;
import com.ruoyi.system.mapper.FinancialKeywordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.FinancialAnnouncementsMapper;
import com.ruoyi.system.domain.FinancialAnnouncements;
import com.ruoyi.system.service.IFinancialAnnouncementsService;
import org.springframework.util.CollectionUtils;

import static com.ruoyi.common.utils.PageUtils.startPage;

/**
 * announcementsService业务层处理
 * 
 * @author ruoyi
 * @date 2024-12-07
 */
@Service
public class FinancialAnnouncementsServiceImpl implements IFinancialAnnouncementsService 
{
    @Autowired
    private FinancialAnnouncementsMapper financialAnnouncementsMapper;

    /**
     * 查询announcements
     * 
     * @param TEXTID announcements主键
     * @return announcements
     */
    @Override
    public FinancialAnnouncements selectFinancialAnnouncementsByTEXTID(String TEXTID)
    {
        return financialAnnouncementsMapper.selectFinancialAnnouncementsByTEXTID(TEXTID);
    }


    @Autowired
    FinancialKeywordMapper financialKeywordMapper;

    /**
     * 查询announcements列表
     * 
     * @param financialAnnouncements announcements
     * @return announcements
     */
    @Override
    public List<FinancialAnnouncements> selectFinancialAnnouncementsList(FinancialAnnouncements financialAnnouncements)
    {
        if (!StringUtils.isEmpty(financialAnnouncements.getParentName())){
            List<FinancialKeyword> financialKeywords = financialKeywordMapper.selectFinancialKeywordByKeyword(financialAnnouncements.getParentName());
            if(!CollectionUtils.isEmpty(financialKeywords)){
                List<String> collect = financialKeywords.stream().map(t -> t.getTypeName()).collect(Collectors.toList());
                startPage();
                return financialAnnouncementsMapper.financialAnnouncementsList(collect);
            }else {
                startPage();
                financialAnnouncements.setF002V(financialAnnouncements.getParentName());
                return financialAnnouncementsMapper.selectFinancialAnnouncementsList(financialAnnouncements);
            }
        }
        return financialAnnouncementsMapper.selectFinancialAnnouncementsList(financialAnnouncements);
    }

    /**
     * 新增announcements
     * 
     * @param financialAnnouncements announcements
     * @return 结果
     */
    @Override
    public int insertFinancialAnnouncements(FinancialAnnouncements financialAnnouncements)
    {
        return financialAnnouncementsMapper.insertFinancialAnnouncements(financialAnnouncements);
    }

    /**
     * 修改announcements
     * 
     * @param financialAnnouncements announcements
     * @return 结果
     */
    @Override
    public int updateFinancialAnnouncements(FinancialAnnouncements financialAnnouncements)
    {
        return financialAnnouncementsMapper.updateFinancialAnnouncements(financialAnnouncements);
    }

    /**
     * 批量删除announcements
     * 
     * @param TEXTIDs 需要删除的announcements主键
     * @return 结果
     */
    @Override
    public int deleteFinancialAnnouncementsByTEXTIDs(String[] TEXTIDs)
    {
        return financialAnnouncementsMapper.deleteFinancialAnnouncementsByTEXTIDs(TEXTIDs);
    }

    /**
     * 删除announcements信息
     * 
     * @param TEXTID announcements主键
     * @return 结果
     */
    @Override
    public int deleteFinancialAnnouncementsByTEXTID(String TEXTID)
    {
        return financialAnnouncementsMapper.deleteFinancialAnnouncementsByTEXTID(TEXTID);
    }

    @Override
    public int selectF002Count(String objectId, Date date) {
        return financialAnnouncementsMapper.selectF002Count(objectId,date);
    }

    @Override
    public int delete(Integer day) {
        return financialAnnouncementsMapper.deleteData(day);
    }

}
